package org.itboys.weixin.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.itboys.admin.tools.WebConstants;
import org.itboys.commons.utils.reflection.Reflections;
import org.itboys.commons.utils.time.TimeUtils;
import org.itboys.framework.resource.ResourceHolder;
import org.itboys.framework.spring.context.SpringContextHolder;
import org.itboys.weixin.constant.WeixinConstants;
import org.itboys.weixin.dto.*;
import org.itboys.weixin.entity.WeixinConfig;
import org.itboys.weixin.entity.WeixinMessage;
import org.itboys.weixin.entity.WeixinMessageDetail;
import org.itboys.weixin.entity.WeixinUser;
import org.itboys.weixin.tools.MemberActionThread;
import org.itboys.weixin.tools.MessageUtils;
import org.itboys.weixin.tools.WeixinUserUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;

/**
 * 微信解析和响应
 * 
 * @author ChenJunhui
 * 
 */
@Service
public class WeixinCoreService {
	private static Logger logger = LoggerFactory
			.getLogger(WeixinCoreService.class);

	@Autowired
	private WeixinMessageService weixinMessageService;
	@Autowired
	private WeixinUserService weixinUserService;
	@Autowired
	private WeixinMessageDetailService weixinMessageDetailService;
	@Autowired
	private ResourceHolder resourceHolder;


	/**
	 * 响应微信的请求
	 * @param requestMap
	 * @param weixinConfig
	 * @return
	 */
	public String doResponseWeixin(Map<String, String> requestMap,
								   WeixinConfig weixinConfig) {
		// 针对需要特殊处理的消息类型 配置调用配置的bean的反射方法来处理消息
		/**
		 * public class 反射的spring的处理bean{ public SpecialMessageResult
		 * 反射方法名(Map<String, String> requestMap,WeixinConfig weixinConfig){
		 */
		if (StringUtils.isNotBlank(weixinConfig.getReflectBean())
				&& StringUtils.isNotBlank(weixinConfig.getReflectMethod())) {
			SpecialMessageResult specialMessageResult = (SpecialMessageResult) Reflections
					.invokeMethod(SpringContextHolder.getBean(weixinConfig
									.getReflectBean()),
							weixinConfig.getReflectMethod(), new Class<?>[] {
									Map.class, WeixinConfig.class },
							new Object[] { requestMap, weixinConfig });
			if (!specialMessageResult.isGoNext()) {
				return specialMessageResult.getResponseMessage();
			}
		}
		String msgType = requestMap.get("MsgType"); // 消息类型
		String fromUserName = requestMap.get("FromUserName");// 发送方帐号（open_id）
		String toUserName = requestMap.get("ToUserName");// 公众帐号
		String respMessage = null;
		WeixinMessage weixinMessage = null;
		if (WeixinConstants.REQ_MESSAGE_TYPE_TEXT.equals(msgType)) {// 接收微信的文本消息
			String keyword = StringUtils.trim(requestMap.get("Content")); // 接收用户发送的文本消息内容
			// 看下有没有关键词匹配的
			// 先做全匹配 到时候做模糊匹配
			weixinMessage = weixinMessageService.getWxmsgByKeywordAndWeixinId(
					weixinConfig.getId(), keyword);
			if (weixinMessage == null) {
				// 就招有没有默认的回复
				weixinMessage = weixinMessageService
						.getDefaultMsgByWeixinId(weixinConfig.getId());
				// 如需要多客服接入,启用该段代码
				/*
				 * TextMessage textMessage = new TextMessage();
				 * textMessage.setMsgType
				 * (WeixinConstants.RESP_MESSAGE_TYPE_SERVER);
				 * textMessage.setToUserName(fromUserName);
				 * textMessage.setFromUserName(toUserName);
				 * textMessage.setCreateTime(new Date().getTime());
				 * textMessage.setFuncFlag(0);
				 *
				 * return MessageUtils.textMessageToXml(textMessage);
				 */
			}
		} else if (msgType.equals(WeixinConstants.REQ_MESSAGE_TYPE_EVENT)) { // 事件类型
			String eventType = requestMap.get("Event");
			// 订阅 用户订阅的时候记录用户的信息 如果用户之前订阅过 则修改状态
			if (eventType.equals(WeixinConstants.EVENT_TYPE_SUBSCRIBE)) { // 用户订阅
				try{
					//System.out.println("消息类型********************************************"+eventType);
					WeixinUserInfo user=WeixinUserUtils.getWeixinUserInfo(weixinConfig.getAppId(),weixinConfig.getAppSecret(),fromUserName);
					/*System.out.println("后user））））））））））））））"+user.toString());
					logger.info("---------------------微信获取的用户"+user.getNickname());
					logger.info("---------------------微信获取的用户"+user.getUnionid());
					logger.info("---------------------微信获取的用户"+user.getOpenid());
					logger.info("---------------------微信获取的用户"+user.getHeadimgurl());*/
				/*	memberService.handleMemberInfo(user.getUnionid(),
							user.getOpenid(),
							user.getNickname(),
							user.getHeadimgurl()
							);*/
				}catch (Exception e){
					e.printStackTrace();
				}

				/*try {
					WeixinUser user = null;
					if (weixinConfig.getType() == WeixinConfig.TYPE_SERVICE
							&& weixinConfig.getPass() == 1) {
						user = WeixinUserUtils.getWeixinUser(weixinConfig.getAppId(), weixinConfig.getAppSecret(), fromUserName, weixinConfig.getId());
					} else {// 订阅好没有取用户的接口
						user = new WeixinUser();
						user.setStatus(1);
						user.setWeixinId(weixinConfig.getId());
						user.setOpenid(fromUserName);
						user.setCity(StringUtils.EMPTY);
						user.setCountry(StringUtils.EMPTY);
						user.setHeadimgurl(StringUtils.EMPTY);
						user.setNickname(StringUtils.EMPTY);
						user.setProvince(StringUtils.EMPTY);
						user.setSex(0);
						user.setSubscribe(1);
						user.setSubscribeTime(new Date());
					}

					user.setWeixinId(weixinConfig.getId());
					WeixinUser existUser = weixinUserService.getWeixinUser(weixinConfig.getId(), fromUserName);
					if (existUser == null) {
						weixinUserService.save(user);
					} else {
						user.setId(existUser.getId());
						weixinUserService.update(user);
					}

					*//**//**
				 * 一下操作是扫描二维码后，设置推荐人的
				 *//**//*
					String eventKey2 = requestMap.get("EventKey");
					if(StringUtils.startsWith(eventKey2, "qrscene_")){//二维码中有自定义的参数  是推荐人的ID
						String recId = eventKey2.substring(8);//截取推荐人的ID
						if(StringUtils.isNotBlank(recId)){//扫的是推广码
							//关注微信公共账号时  扔给线程注册一个会员账号
							MemberActionThread.addMember(user, resourceHolder.getStringValue("addMember"),
									Long.parseLong(recId));
						}else{//直接扫公众号 或者搜索的公众账号名称
							//关注微信公共账号时  扔给线程注册一个会员账号
							MemberActionThread.addMember(user, resourceHolder.getStringValue("addMember"),
									null);
						}
					}else{//直接扫公众号 或者搜索的公众账号名称
						//关注微信公共账号时  扔给线程注册一个会员账号
						MemberActionThread.addMember(user, resourceHolder.getStringValue("addMember"),
								null);
					}

				} catch (Exception e) {
					logger.error("subscribe user error", e);
				}*/
				// 第一次订阅返回默认回复
				/*weixinMessage = weixinMessageService
						.getDefaultMsgByWeixinId(weixinConfig.getId());*/
				weixinMessage=new WeixinMessage();
				weixinMessage.setMsgType(1);
				weixinMessage.setType(1);
				weixinMessage.setDesc("欢迎关注搜鸟私厨。当前时间"+ TimeUtils.formatToTime(new Date()));
			} else if (eventType.equals(WeixinConstants.EVENT_TYPE_UNSUBSCRIBE)) { // 取消订阅
				WeixinUser existUser = weixinUserService.getWeixinUser(
						weixinConfig.getId(), fromUserName);
				if (existUser != null) {// 取消微信用户
					existUser.setCancelTime(new Date());
					existUser.setStatus(0);
					weixinUserService.update(existUser);
				}
				// 取消订阅其实不用管的 也返回默认回复好了
				weixinMessage = weixinMessageService
						.getDefaultMsgByWeixinId(weixinConfig.getId());
			} else if (eventType.equals(WeixinConstants.EVENT_TYPE_CLICK)) {// 遇到点击事件的话
				// 暂时只有自定义菜单有点击事件
				String eventKey = requestMap.get("EventKey");
				if (StringUtils.startsWith(eventKey, "MS_")) {
					weixinMessage = weixinMessageService.getById(Long.parseLong(eventKey.substring(3)));
				}
			} else if (eventType.equals(WeixinConstants.REQ_MESSAGE_TYPE_LOCATION)) {// 获取用户地理位置
				logger.info("---------------------微信获取的用户-地理位置-开始");
				for (String key : requestMap.keySet()) {
					logger.info("---------------------微信获取的用户-地理位置-开始-key="+key+",value="+requestMap.get(key));
				}

			}
		}
		respMessage = prepareWeixinMessage(weixinConfig, fromUserName,
				toUserName, weixinMessage);
		return respMessage;
	}


	private String prepareWeixinMessage(WeixinConfig weixinConfig,
			String fromUserName, String toUserName, WeixinMessage weixinMessage) {
		String respMessage = null;
		if (weixinMessage != null) {
			List<WeixinMessageDetail> messageDetails = weixinMessageDetailService
					.getByWxMsgId(weixinMessage.getId());
			if (!messageDetails.isEmpty()) {
				if (weixinMessage.getMsgType() == WeixinMessage.MSG_TYPE_TEXT) {
					WeixinMessageDetail wd = messageDetails.get(0);
					TextMessage textMessage = new TextMessage();
					textMessage.setToUserName(fromUserName);
					textMessage.setFromUserName(toUserName);
					textMessage.setCreateTime(new Date().getTime());
					textMessage.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_TEXT);
					textMessage.setFuncFlag(0);
					textMessage.setContent(wd.getContent());
					// 将文本消息对象转换成xml字符串
					respMessage = MessageUtils.textMessageToXml(textMessage);
				} else {
					if (weixinMessage.getMsgType() == WeixinMessage.MSG_TYPE_SIGNEL_TUWEN) {
						WeixinMessageDetail wd = messageDetails.get(0);
						WeixinMessageDetail wmd1 = new WeixinMessageDetail();
						wmd1.setImg(wd.getImg());
						wmd1.setUrl(wd.getUrl());
						wmd1.setTitle(wd.getTitle());
						WeixinMessageDetail wmd2 = new WeixinMessageDetail();
						wmd2.setTitle("");
						wmd2.setImg(null);
						wmd2.setUrl(wd.getUrl());
						wmd2.setContent(wd.getContent());
						messageDetails = Lists.newArrayListWithCapacity(2);
						messageDetails.add(wmd1);
						messageDetails.add(wmd2);
					}
					WeixinUser wu = weixinUserService.getWeixinUser(
							weixinConfig.getId(), fromUserName);
					if (wu == null) {
						wu = new WeixinUser();
						wu.setStatus(1);
						wu.setWeixinId(weixinConfig.getId());
						wu.setOpenid(fromUserName);
						wu.setCity(StringUtils.EMPTY);
						wu.setCountry(StringUtils.EMPTY);
						wu.setHeadimgurl(StringUtils.EMPTY);
						wu.setNickname(StringUtils.EMPTY);
						wu.setProvince(StringUtils.EMPTY);
						wu.setSex(0);
						wu.setSubscribe(1);
						wu.setSubscribeTime(new Date());
						try {
							weixinUserService.save(wu);
						} catch (Exception e) {
							logger.error("insert weixinuser error", e);
						}

					}
					// 把微信的每个链接上都加上 2个参数 &wu=微信的用户ID&wid=微信配置表的ID
					for (WeixinMessageDetail wmd : messageDetails) {
						if (StringUtils.isNotBlank(wmd.getUrl())) {
							StringBuilder sb = new StringBuilder();
							sb.append(wmd.getUrl().indexOf("?") != -1 ? "&"
									: "?");
							sb.append(WebConstants.SessionKey.WEIXIN_ID)
									.append("=").append(weixinConfig.getId());
							if (wu != null) {
								sb.append("&")
										.append(WebConstants.SessionKey.WEIXIN_USER_ID)
										.append("=").append(wu.getId());
							}
							wmd.setUrl(wmd.getUrl() + sb.toString());
						}
					}
					// 讲消息转成 图文格式
					List<Article> articleList = MessageUtils
							.weixinMessageToArticles(messageDetails,
									resourceHolder.getStringValue("imgRoot"));
					// 创建图文消息
					NewsMessage newsMessage = new NewsMessage();
					newsMessage.setToUserName(fromUserName);
					newsMessage.setFromUserName(toUserName);
					newsMessage.setCreateTime(new Date().getTime());
					newsMessage
							.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_NEWS);
					newsMessage.setFuncFlag(0);
					newsMessage.setArticleCount(articleList.size());// 设置图文消息个数
					newsMessage.setArticles(articleList);// 设置图文消息包含的图文集合
					respMessage = MessageUtils.newsMessageToXml(newsMessage);// 将图文消息对象转换成xml字符串
				}
			}
		}
		return respMessage;
	}

	/**
	 * emoji表情转换(hex -> utf-16)
	 * 
	 * @return
	 */
	public static String emoji(int hexEmoji) {
		return String.valueOf(Character.toChars(hexEmoji));
	}

	/**
	 * 响应微信的请求 并返回相关的xml 这个是测试代码
	 * 
	 * @param messageMap
	 * @param projectId
	 */
	/*
	 * public String doReqAndReturnResXml(Map<String, String> requestMap,long
	 * weixinId){ String msgType = requestMap.get("MsgType"); // 消息类型 String
	 * fromUserName = requestMap.get("FromUserName");// 发送方帐号（open_id） String
	 * toUserName = requestMap.get("ToUserName");// 公众帐号 String respMessage =
	 * null;
	 * if(WeixinConstants.REQ_MESSAGE_TYPE_TEXT.equals(msgType)){//接收微信的文本消息
	 * String content = StringUtils.trim(requestMap.get("Content")); //
	 * 接收用户发送的文本消息内容 // 创建图文消息 NewsMessage newsMessage = new NewsMessage();
	 * newsMessage.setToUserName(fromUserName);
	 * newsMessage.setFromUserName(toUserName); newsMessage.setCreateTime(new
	 * Date().getTime());
	 * newsMessage.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_NEWS);
	 * //newsMessage.setFuncFlag(0); List<Article> articleList = new
	 * ArrayList<Article>();
	 * 
	 * if ("1".equals(content)) { // 测试单图文消息 包含图片 和链接 Article article1 = new
	 * Article(); article1.setTitle("圣代官网"); article1.setDescription("");
	 * article1
	 * .setPicUrl("http://static.o2o2m.com/sunday/images/index/logo.jpg");
	 * article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("点击进入");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * newsMessage.setArticleCount(articleList.size());// 设置图文消息个数
	 * newsMessage.setArticles(articleList);// 设置图文消息包含的图文集合 respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage);// 将图文消息对象转换成xml字符串 }else if
	 * ("2".equals(content)) {// 测试多图文消息 Article article1 = new Article();
	 * article1.setTitle("圣代每日最新资讯"); article1.setDescription("");
	 * article1.setPicUrl
	 * ("http://static.o2o2m.com/sunday/images/index/logo.jpg");
	 * article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("圣代获得高新技术企业奖");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article3 = new Article(); article3.setTitle("圣代帮助很多的企业成功");
	 * article3.setDescription(""); article3.setPicUrl("");
	 * article3.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article4 = new Article(); article4.setTitle("圣代拥有全杭州最优秀人才");
	 * article4.setDescription(""); article4.setPicUrl("");
	 * article4.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * articleList.add(article3); articleList.add(article4);
	 * newsMessage.setArticleCount(articleList.size());
	 * newsMessage.setArticles(articleList); respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage); }else{ // 默认回复此文本消息
	 * TextMessage textMessage = new TextMessage();
	 * textMessage.setToUserName(fromUserName);
	 * textMessage.setFromUserName(toUserName); textMessage.setCreateTime(new
	 * Date().getTime());
	 * textMessage.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_TEXT);
	 * textMessage.setFuncFlag(0); StringBuilder contentMsg = new
	 * StringBuilder();
	 * contentMsg.append("欢迎访问<a href=\"http://webapp.sunday-mobi.com\">圣代官网</a>"
	 * ).append("\n"); contentMsg.append("您好，我是圣代客服孙雯!").append("\n");
	 * contentMsg.append("1  进入圣代官网").append("\n");
	 * contentMsg.append("2  查看最新资讯").append("\n");
	 * contentMsg.append("测试发地理位置我们帮你查附近的二手电脑").append("\n");
	 * contentMsg.append("测试发下你的照片我们做明星脸匹配").append("\n");
	 * contentMsg.append("点击查看 <a href=\"http://webapp.sunday-mobi.com\">帮助手册</a>"
	 * ); textMessage.setContent(contentMsg.toString()); // 将文本消息对象转换成xml字符串
	 * respMessage = MessageUtils.textMessageToXml(textMessage);
	 * 
	 * 
	 * Article article1 = new Article(); article1.setTitle("测试默认回复");
	 * article1.setDescription("");
	 * article1.setPicUrl("http://static.o2o2m.com/sunday/images/index/logo.jpg"
	 * ); article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("关于圣代");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article3 = new Article(); article3.setTitle("圣代最新资讯");
	 * article3.setDescription(""); article3.setPicUrl("");
	 * article3.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * 
	 * Article article4 = new Article(); article4.setTitle("会员中心");
	 * article4.setDescription(""); article4.setPicUrl("");
	 * article4.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * articleList.add(article3); articleList.add(article4);
	 * 
	 * newsMessage.setArticleCount(articleList.size());
	 * newsMessage.setArticles(articleList); respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage); } }else
	 * if(WeixinConstants.REQ_MESSAGE_TYPE_LOCATION.equals(msgType)){ //
	 * 默认回复此文本消息 TextMessage textMessage = new TextMessage();
	 * textMessage.setToUserName(fromUserName);
	 * textMessage.setFromUserName(toUserName); textMessage.setCreateTime(new
	 * Date().getTime());
	 * textMessage.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_TEXT);
	 * textMessage.setFuncFlag(0); String x = requestMap.get("Location_X");
	 * String y = requestMap.get("Location_Y"); String label =
	 * requestMap.get("Label");
	 * textMessage.setContent("地理位置("+x+","+y+"),"+label+",附近有个叫任阳利的有2台二手电脑买");
	 * // 将文本消息对象转换成xml字符串 respMessage =
	 * MessageUtils.textMessageToXml(textMessage); }else
	 * if(WeixinConstants.REQ_MESSAGE_TYPE_IMAGE.equals(msgType)){ // 创建图文消息
	 * NewsMessage newsMessage = new NewsMessage();
	 * newsMessage.setToUserName(fromUserName);
	 * newsMessage.setFromUserName(toUserName); newsMessage.setCreateTime(new
	 * Date().getTime());
	 * newsMessage.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_NEWS);
	 * newsMessage.setFuncFlag(0);
	 * 
	 * String pic = requestMap.get("PicUrl"); List<Article> articleList = new
	 * ArrayList<Article>(); Article article = new Article();
	 * article.setTitle("哎呦 你长的像linux专家任阳利");
	 * article.setDescription("点击查看分析报告。");
	 * article.setPicUrl("http://static2.o2o2m.com/img/1.jpg");
	 * article.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article1 = new Article(); article1.setTitle("对比下");
	 * article1.setDescription(""); article1.setPicUrl(pic);
	 * article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * articleList.add(article); articleList.add(article1);
	 * newsMessage.setArticleCount(articleList.size());// 设置图文消息个数
	 * newsMessage.setArticles(articleList);// 设置图文消息包含的图文集合 respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage);// 将图文消息对象转换成xml字符串 } else if
	 * (msgType.equals(WeixinConstants.REQ_MESSAGE_TYPE_EVENT)) { // 事件类型 String
	 * eventType = requestMap.get("Event"); // 订阅 if
	 * (eventType.equals(WeixinConstants.EVENT_TYPE_SUBSCRIBE)) { // 默认回复此文本消息
	 * TextMessage textMessage = new TextMessage();
	 * textMessage.setToUserName(fromUserName);
	 * textMessage.setFromUserName(toUserName); textMessage.setCreateTime(new
	 * Date().getTime());
	 * textMessage.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_TEXT);
	 * textMessage.setFuncFlag(0); StringBuilder contentMsg = new
	 * StringBuilder(); contentMsg.append("谢谢您的关注！：").append("\n\n");
	 * contentMsg.
	 * append("欢迎访问<a href=\"http://webapp.sunday-mobi.com\">圣代官网</a>"
	 * ).append("\n"); contentMsg.append("您好，我是圣代客服孙雯!").append("\n");
	 * contentMsg.append("1  进入圣代官网").append("\n");
	 * contentMsg.append("2  查看最新资讯").append("\n");
	 * contentMsg.append("测试发地理位置我们帮你查附近的二手电脑").append("\n");
	 * contentMsg.append("测试发下你的照片我们做明星脸匹配").append("\n");
	 * contentMsg.append("点击查看 <a href=\"http://webapp.sunday-mobi.com\">帮助手册</a>"
	 * ); textMessage.setContent(contentMsg.toString()); // 将文本消息对象转换成xml字符串
	 * respMessage = MessageUtils.textMessageToXml(textMessage); // 创建图文消息
	 * NewsMessage newsMessage = new NewsMessage();
	 * newsMessage.setToUserName(fromUserName);
	 * newsMessage.setFromUserName(toUserName); newsMessage.setCreateTime(new
	 * Date().getTime());
	 * newsMessage.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_NEWS);
	 * //newsMessage.setFuncFlag(0); List<Article> articleList = new
	 * ArrayList<Article>();
	 * 
	 * Article article1 = new Article(); article1.setTitle("感谢关注圣代");
	 * article1.setDescription("");
	 * article1.setPicUrl("http://static.o2o2m.com/sunday/images/index/logo.jpg"
	 * ); article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("进入圣代");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * 
	 * newsMessage.setArticleCount(articleList.size());
	 * newsMessage.setArticles(articleList); respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage); }else if
	 * (eventType.equals(WeixinConstants.EVENT_TYPE_UNSUBSCRIBE)) {
	 * logger.info(fromUserName+"取消了关注 我们就不管了"); }else
	 * if(eventType.equals(WeixinConstants.EVENT_TYPE_CLICK)){ //自定义菜单的点击事件了
	 * //事件的key 根据key去做什么 String eventKey = requestMap.get("EventKey"); //
	 * 创建图文消息 NewsMessage newsMessage = new NewsMessage();
	 * newsMessage.setToUserName(fromUserName);
	 * newsMessage.setFromUserName(toUserName); newsMessage.setCreateTime(new
	 * Date().getTime());
	 * newsMessage.setMsgType(WeixinConstants.RESP_MESSAGE_TYPE_NEWS);
	 * newsMessage.setFuncFlag(0); List<Article> articleList = new
	 * ArrayList<Article>(); if(eventKey.equals("ENTER_SUNDAY_001")){ Article
	 * article1 = new Article(); article1.setTitle("圣代官网");
	 * article1.setDescription("");
	 * article1.setPicUrl("http://static.o2o2m.com/sunday/images/index/logo.jpg"
	 * ); article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("点击进入");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * newsMessage.setArticleCount(articleList.size());// 设置图文消息个数
	 * newsMessage.setArticles(articleList);// 设置图文消息包含的图文集合 respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage);// 将图文消息对象转换成xml字符串 }else
	 * if(eventKey.equals("SUNDAY_NEWS_001")){ Article article1 = new Article();
	 * article1.setTitle("圣代每日最新资讯"); article1.setDescription("");
	 * article1.setPicUrl
	 * ("http://static.o2o2m.com/sunday/images/index/logo.jpg");
	 * article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("圣代获得高新技术企业奖");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article3 = new Article(); article3.setTitle("圣代帮助很多的企业成功");
	 * article3.setDescription(""); article3.setPicUrl("");
	 * article3.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article4 = new Article(); article4.setTitle("圣代拥有全杭州最优秀人才");
	 * article4.setDescription(""); article4.setPicUrl("");
	 * article4.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * articleList.add(article3); articleList.add(article4);
	 * newsMessage.setArticleCount(articleList.size());
	 * newsMessage.setArticles(articleList); respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage); }else
	 * if(eventKey.equals("TEST1_001")){ Article article1 = new Article();
	 * article1.setTitle(""); article1.setDescription("");
	 * article1.setPicUrl("http://static.o2o2m.com/sunday/images/index/logo.jpg"
	 * ); article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("点击进入我的订单");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * newsMessage.setArticleCount(articleList.size());// 设置图文消息个数
	 * newsMessage.setArticles(articleList);// 设置图文消息包含的图文集合 respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage);// 将图文消息对象转换成xml字符串 }else
	 * if(eventKey.equals("TEST2_001")){ Article article1 = new Article();
	 * article1.setTitle(""); article1.setDescription("");
	 * article1.setPicUrl("http://static.o2o2m.com/sunday/images/index/logo.jpg"
	 * ); article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("点击进入我的提问");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * newsMessage.setArticleCount(articleList.size());// 设置图文消息个数
	 * newsMessage.setArticles(articleList);// 设置图文消息包含的图文集合 respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage);// 将图文消息对象转换成xml字符串 }else
	 * if(eventKey.equals("TEST3_001")){ Article article1 = new Article();
	 * article1.setTitle(""); article1.setDescription("");
	 * article1.setPicUrl("http://static.o2o2m.com/sunday/images/index/logo.jpg"
	 * ); article1.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * Article article2 = new Article(); article2.setTitle("点击进入我的收藏");
	 * article2.setDescription(""); article2.setPicUrl("");
	 * article2.setUrl("http://webapp.sunday-mobi.com/");
	 * 
	 * articleList.add(article1); articleList.add(article2);
	 * newsMessage.setArticleCount(articleList.size());// 设置图文消息个数
	 * newsMessage.setArticles(articleList);// 设置图文消息包含的图文集合 respMessage =
	 * MessageUtils.newsMessageToXml(newsMessage);// 将图文消息对象转换成xml字符串 }
	 * 
	 * }
	 * 
	 * } return respMessage; }
	 */
}
